#include "../tools.h"




// 理顺逻辑
int main(int argc, char const *argv[])
{
    int arr[][4] = {
        {0, 0, 2, 4},
        {0, 2, 2, 2},
        {0, 4, 2, 2},
        {8, 8, 2, 2}
    };

    int size = 4;
    for(int i = 0; i < size; ++i){
        int flag = true;
        while(flag){
            flag = false;
            int pre = -1;
            for(int j = 0; j < size; ++j){
                if(arr[i][j] != 0){
                    if(pre == -1){
                        arr[i][0] = arr[i][j];
                        pre = 0;
                    }
                    else{
                        if(arr[i][j] == arr[i][pre]){
                            arr[i][pre] <<= 1;
                            flag = true;
                        }
                        else{
                            arr[i][++pre] = arr[i][j];
                        }
                    }

                    if(pre != j) arr[i][j] = 0;
                }
            }
        }
    }

    for(int i = 0; i < size; ++i){
        for(int j = 0; j < size; ++j)
            cout << arr[i][j] << " ";
        cout << endl;
    }


    return 0;
}
